#include <iostream>
#include <vector>

using namespace std;
class Solution {
public:
    int GetMaxReduced(const vector<int>& codeStats)
    {
        int maxCountTime = 0;
        int left = 0;
        int len = codeStats.size();
        int i = 0;
        int j;
        while (i < len) {
            left = codeStats[i];
            if (left < 1 || left > 1000000) {
                return 0;
            }
            int middleResult;
            j = i + 1;
            while(j < len) {
                middleResult = left - codeStats[j];
                if (middleResult > 0 && middleResult > maxCountTime) {
                    maxCountTime = max(maxCountTime, middleResult);
                }
                j++;
            }
            i++;
        }
        return maxCountTime;
    }
};

inline int ReadInt()
{
    int number;
    std::cin >> number;
    return number;
}
template<typename T>
inline vector<T> ReadVector(int size)
{
    vector<T> objects(size);
    for (int i = 0; i < size; i++) {
        cin >> objects[i];
    }
    return objects;
}
int main() {
    int timeCount = ReadInt();
    if (timeCount < 1 || timeCount > 100000) {
        return 0;
    }
    vector<int> codeStats = ReadVector<int>(timeCount);
    Solution solu;
    cout << solu.GetMaxReduced(codeStats);
    return 0;
}
